package com.baizhi.service.Impl;

import com.baizhi.dao.PhoneDao;
import com.baizhi.Phone;
import com.baizhi.service.PhoneService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PhoneServiceImpl implements PhoneService {
    @Autowired
    private PhoneDao pd;
    @Override
    public PageInfo<Phone> selectPage(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Phone> phones = pd.seletAll();
        PageInfo<Phone> p=new PageInfo<>(phones);
        return p;
    }

    @Override
    public boolean addPhone(Phone p) {
        int insert = pd.insert(p);
        if (insert!=0){
            return true;
        }
        return false;
    }

    @Override
    public boolean deletePhone(int id) {
        int i = pd.deleteById(id);
        if (i!=0){
            return true;
        }
        return false;
    }

    @Override
    public Phone select(int id) {
        Phone phone = pd.selectById(id);
        return phone;
    }

    @Override
    public boolean update(Phone p,int id) {
        QueryWrapper<Phone> c=new QueryWrapper<>();
        c.eq("id",id);
        int update = pd.update(p, c);
        if (update!=0){
            return  true;
        }
        return false;
    }

    @Override
    public void deleteAll(List<Integer> ids) {
        pd.deleteAllList(ids);
    }
}
